package string;

import serialize.MaliciousUserReq;
import utils.Log;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class StringTest2 {

    //日志最长保留时间
    private static final int LOG_EXPIRE_DAY = 7;
    /**
     * xlog文件后缀名
     */
    private final static String XLOG_FILE_SUFFIX_NAME = ".xlog";

    /**
     * xlog文件名后缀日期格式
     */
    private final static String XLOG_FILE_NAME_SUFFIX_DATE_FORMAT = "yyyyMMdd";


    public static void main(String[] args) {
        String[] logFiles = {"merchant_ant_20190116.xlog", "merchant_20190122.xlog", "merchant_leakcanary_20190115.xlog"};

        DateFormat dateFormat = new SimpleDateFormat(XLOG_FILE_NAME_SUFFIX_DATE_FORMAT,
                Locale.US);
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, 1-LOG_EXPIRE_DAY);
        String limitDate = dateFormat.format(calendar.getTime());
        Log.vn("limitDate:" + limitDate);
        for (String logFile : logFiles) {

            int start = logFile.length()-XLOG_FILE_SUFFIX_NAME.length()-XLOG_FILE_NAME_SUFFIX_DATE_FORMAT.length();
            int end = start + XLOG_FILE_NAME_SUFFIX_DATE_FORMAT.length();
            String logDate = logFile.substring(start, end);


            Log.vn("logDate:" + logDate);
            // compare limit date
            if (limitDate.compareTo(logDate) < 0) {
                Log.vn("continue");
            }

        }

        String suffix = getFileExt("1.txt");
        Log.vn("suffix:" + suffix);
    }


    public static String getFileExt(String fullName) {
        if (null == fullName)
            return "";
        int index = fullName.lastIndexOf('.');
        if (index == -1)
            return "";
        return fullName.substring(index + 1);
    }

}
